/// faichou 2017-01-11

var app = getApp()
var util=require('../../utils/util')
var dialog=require('../../utils/dialog')
var req=require('./addressReq.js')
var notificationCenter=require('../../utils/WxNotificationCenter')

Page({
	data:{
		addrArray:[],
	},
	onLoad:function(options){
		
	},
	onReady:function(){
		
	},
	onShow:function(){
		var that = this
		req.requestAllAddr(function(data){
			let resArr = data.returnData.currentList
			that.setData({ 
				addrArray: resArr 
			})
			}, function(err){
				dialog.warn('获取失败，请稍后重试')
		})
	},
	onHide:function(){
		
	},
	onUnload:function(){
		
	},
	onPullDownRefresh:function(){
		
	},
	onReachBottom:function(){
		
	},
	didSelectAddress: function(e){
		let index = e.currentTarget.dataset.index
		console.log(index)
		// 这里应该将this.addrArray[index]回传给提交订单页面，并navigateBack回去
		notificationCenter.postNotification('changeAddress', this.data.addrArray[index])
		wx.navigateBack()
	},
	addAddress: function(){
		let addressEditPath = './addressEdit?justAdd=1'
		app.globalData.receiveInfo = null // 添加地址，receiveInfo都为空
		wx.navigateTo({
		  url: addressEditPath
		})
	}
})		